﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Brain.Animation
{
    /// <summary>
    /// This is a TimeLine of Animations
    /// </summary>
    public class BaseAnimationTimeLine
    {
        public virtual List<IBaseAnimation> Animations { get; set; }

        public virtual bool Play { get; set; }

        public BaseAnimationTimeLine()
        {
            Play = true;
        }

        public virtual void AddAnimation(IBaseAnimation Animation)
        {
            if (Animations == null)
            {
                Animations = new List<IBaseAnimation>();
            }
            this.Animations.Add(Animation);
        }

        public virtual void Update()
        {
            if (Play && Engine.Instance.AnimationManager.Playing && Animations != null)
            {
                for (int i = 0; i < Animations.Count; i++)
                {
                    IBaseAnimation animation = Animations[i];
                    float FrameDif = Engine.Instance.AnimationManager.FrameDifference; ;
                    float CurrentFrame = Engine.Instance.AnimationManager.CurrentFrame;

                    if (animation.Loop && CurrentFrame >= animation.StartFrame)
                    {
                        animation.UpdateLoop(FrameDif);
                    }
                    else
                    {
                        if (CurrentFrame >= animation.StartFrame &&
                            CurrentFrame <= animation.AnimationEnd)
                        {
                            animation.Update((int)(CurrentFrame - (float)animation.StartFrame));
                        }
                    }
                }
            }
        }

    }
}
